/**
 * <h3>Class description</h3>
 * <h4>Description</h4>
 *  鏌ヨ鏉′欢
 * <h4>Special Notes</h4>
 * 
 *
 * @ver 0.1
 * @author Terry
* 2011-5-5
 */
package com.gamutsoft.amb.common.bean;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.gamutsoft.amb.common.constants.Constants;
import com.gamutsoft.amb.common.util.PageUtil;

public class QueryExample
{
	private List<CondictionsBean> condictions = new ArrayList<CondictionsBean>();
	
	private List<CondictionsBean> orCondictions = new ArrayList<CondictionsBean>();
	
	private Map<String , Map<String , Date>> timeCondictions = new HashMap<String , Map<String , Date>>();
	
	private List<String> orders;
	
	private String groupBy = "";
	
	private String mySql = "";
	
	private PageUtil pageUtil = null;
	
	public QueryExample addCondictions(String property , String condiction , Object value){
		CondictionsBean bean = new CondictionsBean();
		bean.setProperty( property );
		bean.setCondiction( condiction );
		bean.setValue( value );
		bean.setRelation( Constants.RELATION_AND);
		condictions.add( bean );
		return this;
	}
	public QueryExample addOrCondictions(String property , String condiction , Object value){
		CondictionsBean bean = new CondictionsBean();
		bean.setProperty( property );
		bean.setCondiction( condiction );
		bean.setValue( value );
		bean.setRelation( "or" );
		orCondictions.add( bean );
		return this;
	}
	/**
	 * 甯elation , 鐢ㄤ簬 and 鍜�or
	 * @param property
	 * @param condiction
	 * @param relation
	 * @param value
	 * @return
	 */
	public QueryExample addCondictions(String property , String condiction , String relation , Object value){
		CondictionsBean bean = new CondictionsBean();
		bean.setProperty( property );
		bean.setCondiction( condiction );
		bean.setValue( value );
		bean.setRelation( relation );
		condictions.add( bean );
		return this;
	}
	
	public QueryExample addCondictions(CondictionsBean bean){
		condictions.add( bean );
		return this;
	}
	
	public QueryExample addTimeCondictions(String property , Date start , Date end){
		Map<String ,Date> timeMap = new HashMap<String , Date>();
		timeMap.put( "start", start );
		timeMap.put( "end", end );
		timeCondictions.put( property, timeMap );
		return this;
	}
	
	public QueryExample addTimeCondictions(String property , Map<String , Date> timeMap){
		timeCondictions.put( property, timeMap );
		return this;
	}
	
	public Map<String , Date> getTimeMap(String key){
		return timeCondictions.get( key );
	}
	
	public QueryExample addOrderBy(String orderBy){
		if(orders == null){
			orders = new ArrayList<String>();
		}
		orders.add( orderBy );
		return this;
	}

	
	public List<CondictionsBean> getCondictions()
	{
		return condictions;
	}

	public void setCondictions(List<CondictionsBean> condictions)
	{
		this.condictions = condictions;
	}
	
	public Map<String, Map<String, Date>> getTimeCondictions()
	{
		return timeCondictions;
	}

	public void setTimeCondictions(Map<String, Map<String, Date>> timeCondictions)
	{
		this.timeCondictions = timeCondictions;
	}

	
	public List<String> getOrders()
	{
		return orders;
	}

	
	public void setOrders(List<String> orders)
	{
		this.orders = orders;
	}

	
	public PageUtil getPageUtil()
	{
		return pageUtil;
	}

	
	public void setPageUtil(PageUtil pageUtil)
	{
		this.pageUtil = pageUtil;
	}

	
	public String getGroupBy()
	{
		return groupBy;
	}

	
	public void setGroupBy(String groupBy)
	{
		this.groupBy = groupBy;
	}
	
	public List<CondictionsBean> getOrCondictions()
	{
		return orCondictions;
	}
	
	public void setOrCondictions(List<CondictionsBean> orCondictions)
	{
		this.orCondictions = orCondictions;
	}
	
	public String getMySql()
	{
		return mySql;
	}
	
	public void setMySql(String mySql)
	{
		this.mySql = mySql;
	}
	
}

